<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd',changeMonth: true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>出库时间</th>
	<td>
		<input type="text" name="begin_shipped_time" class="datepicker" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : date('Y-m-01', CURRENT_TIMESTAMP)?>"/> to
		<input type="text" name="end_shipped_time" class="datepicker" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : date('Y-m-d', CURRENT_TIMESTAMP)?>"/>
	</td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
		<?foreach ($shop_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id'])) echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?=isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id'] ? 'selected="selected"' : ''?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>SKU</th>
	<td><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>"/></td>
</tr>
<tr>
	<td></td>
	<td>
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
	<td>
	<?if (!empty($url_arr)):?>
		<a href="<?=url('Datacenter::Sales/SalesByShopAndCountryDownload', $url_arr)?>"><input type="button" class="button" value="下载报表"/></a>
	<?endif;?>
	</td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($_GET['is_search']) && $_GET['is_search'] == 1 && ! empty($report)):?>
<table class="list_table" width="50%">
<tr>
	<th>仓库</th>
	<th>店铺</th>
	<th>产品编号</th>
	<th>产品名称</th>
	<th>国家</th>
	<th>销售数</th>
</tr>
<?foreach ($report as $warehouse_name => $rw):?>
	<?foreach ($rw['shops'] as $shop_name => $rws):?>
		<?foreach ($rws['product_numbers'] as $product_number => $rwsp):?>
			<?foreach ($rwsp['countrys'] as $country => $rwspc):?>
			<tr>
				<td><?=$warehouse_name?></td>
				<td><?=$shop_name?></td>
				<td><?=$product_number?></td>
				<td><?=$rwsp['product_name']?></td>
				<td><?=$country?></td>
				<td><?=$rwspc['quantity']?></td>
			</tr>
			<?endforeach;?>
		<?endforeach;?>
	<?endforeach;?>
<?endforeach;?>
</table>
<?endif;?>
<?php $this->_endblock();?>